package tw.com.book.domain.dao;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import tw.com.book.componet.CursorUtils;
import tw.com.book.componet.DBContract;
import tw.com.book.componet.IssueBussinessException;
import tw.com.book.componet.Msg;
import tw.com.book.componet.PairValue;
import tw.com.book.componet.TableContent;
import tw.com.book.componet.VoUtils;
import tw.com.book.domain.V001Type;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class V001DAO extends BaseDAO {

	private static final String TAG = V001DAO.class.getCanonicalName();

	public V001DAO(SQLiteDatabase sqlite, Context ct) {
		super(sqlite, ct);
		// TODO Auto-generated constructor stub
	}

	public void insert(V001Type type) throws IssueBussinessException {

		try {
			final ContentValues map = VoUtils.getContentValues(type,
					this.getCt());
			//
			// BookApplication app =
			//
			// (BookApplication) this.getCt().getApplicationContext();
			//
			// TableContent table =
			// app.getTable(type.getClass().getSimpleName());

			this.getSqlite().insert(DBContract.V001_TABLE, null, map);
		} catch (IssueBussinessException e) {
			Log.v(TAG, e.getMessage());
			throw e;
		} catch (Exception e) {
			Log.v(TAG, e.getMessage());
			throw new IssueBussinessException(Msg.E003);
		}

	}

	public List<V001Type> selectAll() throws IssueBussinessException {

		final Cursor cur = this.getSqlite().rawQuery("select * from v001 where status=? ;",
				new String[] {"A"});

		return CursorUtils.toConvertz(cur, V001Type.class, this.getCt());

	}
}
